package com.cloud.core.http;

import android.content.Intent;

import androidx.annotation.CallSuper;

import com.cloud.core.http.error.ApiException;
import com.cloud.core.http.error.ERROR;
import com.cloud.core.http.error.ExceptionEngine;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @Author:Chen
 * @Date: 2021-01-14 14:37
 * @Description:
 */
public abstract class BaseObserver<T> implements Observer<T> {

    public BaseObserver() {
    }

    @Override
    public void onSubscribe(Disposable d) {

    }

    @CallSuper
    @Override
    public void onNext(T t) {
        onSuccess(t);
    }

    @CallSuper
    @Override
    public void onError(Throwable e) {
        ApiException apiException = ExceptionEngine.handleException(e);
        onError(apiException.message);
        onComplete();
    }

    @Override
    public void onComplete() {
    }

    public abstract void onSuccess(T t);

    public abstract void onError(String msg);
}
